<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AWTK-JAVA: awtk.AssetsManager类 参考</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">AWTK-JAVA
   </div>
   <div id="projectbrief">AWTK JAVA API</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','搜索');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>awtk</b></li><li class="navelem"><a class="el" href="classawtk_1_1_assets_manager.html">AssetsManager</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public 成员函数</a> &#124;
<a href="#pub-static-methods">静态 Public 成员函数</a> &#124;
<a href="#pub-attribs">Public 属性</a> &#124;
<a href="classawtk_1_1_assets_manager-members.html">所有成员列表</a>  </div>
  <div class="headertitle">
<div class="title">awtk.AssetsManager类 参考</div>  </div>
</div><!--header-->
<div class="contents">
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public 成员函数</h2></td></tr>
<tr class="memitem:a48db43eb0f1843f65e5c26be49b25ff7"><td class="memItemLeft" align="right" valign="top"><a id="a48db43eb0f1843f65e5c26be49b25ff7"></a>
&#160;</td><td class="memItemRight" valign="bottom"><b>AssetsManager</b> (long nativeObj)</td></tr>
<tr class="separator:a48db43eb0f1843f65e5c26be49b25ff7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af91442e58d979a2326938e6d22cb2435"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classawtk_1_1_asset_info.html">AssetInfo</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classawtk_1_1_assets_manager.html#af91442e58d979a2326938e6d22cb2435">ref</a> (<a class="el" href="enumawtk_1_1_asset_type.html">AssetType</a> type, String name)</td></tr>
<tr class="separator:af91442e58d979a2326938e6d22cb2435"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a93fbd1784f39c0f37d029ad57d808103"><td class="memItemLeft" align="right" valign="top"><a class="el" href="enumawtk_1_1_ret.html">Ret</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classawtk_1_1_assets_manager.html#a93fbd1784f39c0f37d029ad57d808103">unref</a> (<a class="el" href="classawtk_1_1_asset_info.html">AssetInfo</a> info)</td></tr>
<tr class="separator:a93fbd1784f39c0f37d029ad57d808103"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-static-methods"></a>
静态 Public 成员函数</h2></td></tr>
<tr class="memitem:a59972541d1f4b2cbd104da0456043fab"><td class="memItemLeft" align="right" valign="top"><a id="a59972541d1f4b2cbd104da0456043fab"></a>
static <a class="el" href="classawtk_1_1_assets_manager.html">AssetsManager</a>&#160;</td><td class="memItemRight" valign="bottom"><b>cast</b> (long nativeObj)</td></tr>
<tr class="separator:a59972541d1f4b2cbd104da0456043fab"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a62385f94a5ef47336442f7b22221cb58"><td class="memItemLeft" align="right" valign="top">static <a class="el" href="classawtk_1_1_assets_manager.html">AssetsManager</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classawtk_1_1_assets_manager.html#a62385f94a5ef47336442f7b22221cb58">instance</a> ()</td></tr>
<tr class="separator:a62385f94a5ef47336442f7b22221cb58"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-attribs"></a>
Public 属性</h2></td></tr>
<tr class="memitem:a5ca15a7b4366d5f826324c3751200500"><td class="memItemLeft" align="right" valign="top"><a id="a5ca15a7b4366d5f826324c3751200500"></a>
long&#160;</td><td class="memItemRight" valign="bottom"><b>nativeObj</b></td></tr>
<tr class="separator:a5ca15a7b4366d5f826324c3751200500"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">详细描述</h2>
<div class="textblock"><p>资源管理器。 这里的资源管理器并非Windows下的文件浏览器，而是负责对各种资源，比如字体、主题、图片、界面数据、字符串和其它数据的进行集中管理的组件。引入资源管理器的目的有以下几个：</p>
<ul>
<li>让上层不需要了解存储的方式。 在没有文件系统时或者内存紧缺时，把资源转成常量数组直接编译到代码中。在有文件系统而且内存充足时，资源放在文件系统中。在有网络时，资源也可以存放在服务器上(暂未实现)。资源管理器为上层提供统一的接口，让上层而不用关心底层的存储方式。</li>
<li>让上层不需要了解资源的具体格式。 比如一个名为earth的图片，没有文件系统或内存紧缺，图片直接用位图数据格式存在ROM中，而有文件系统时，则用PNG格式存放在文件系统中。资源管理器让上层不需要关心图片的格式，访问时指定图片的名称即可(不用指定扩展名)。</li>
<li>让上层不需要了解屏幕的密度。 不同的屏幕密度下需要加载不同的图片，比如MacPro的Retina屏就需要用双倍解析度的图片，否则就出现界面模糊。AWTK以后会支持PC软件和手机软件的开发，所以资源管理器需要为此提供支持，让上层不需关心屏幕的密度。</li>
<li>对资源进行内存缓存。 不同类型的资源使用方式是不一样的，比如字体和主题加载之后会一直使用，UI文件在生成界面之后就暂时不需要了，PNG文件解码之后就只需要保留解码的位图数据即可。资源管理器配合图片管理器等其它组件实现资源的自动缓存。</li>
</ul>
<p>当从文件系统加载资源时，目录结构要求如下：</p>
<div class="fragment"><div class="line">assets/{theme}/raw/</div><div class="line">fonts   字体</div><div class="line">images  图片</div><div class="line">x1   普通密度屏幕的图片。</div><div class="line">x2   2倍密度屏幕的图片。</div><div class="line">x3   3倍密度屏幕的图片。</div><div class="line">xx   密度无关的图片。</div><div class="line">strings 需要翻译的字符串。</div><div class="line">styles  主题数据。</div><div class="line">ui      UI描述数据。</div></div><!-- fragment --> </div><h2 class="groupheader">成员函数说明</h2>
<a id="a62385f94a5ef47336442f7b22221cb58"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a62385f94a5ef47336442f7b22221cb58">&#9670;&nbsp;</a></span>instance()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static <a class="el" href="classawtk_1_1_assets_manager.html">AssetsManager</a> awtk.AssetsManager.instance </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>获取缺省资源管理器。</p>
<dl class="section return"><dt>返回</dt><dd>返回asset manager对象。 </dd></dl>

</div>
</div>
<a id="af91442e58d979a2326938e6d22cb2435"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af91442e58d979a2326938e6d22cb2435">&#9670;&nbsp;</a></span>ref()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classawtk_1_1_asset_info.html">AssetInfo</a> awtk.AssetsManager.ref </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="enumawtk_1_1_asset_type.html">AssetType</a>&#160;</td>
          <td class="paramname"><em>type</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">String&#160;</td>
          <td class="paramname"><em>name</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>在资源管理器的缓存中查找指定的资源并引用它，如果缓存中不存在，尝试加载该资源。</p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">type</td><td>资源的类型。 </td></tr>
    <tr><td class="paramname">name</td><td>资源的名称。</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>返回</dt><dd>返回资源。 </dd></dl>

</div>
</div>
<a id="a93fbd1784f39c0f37d029ad57d808103"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a93fbd1784f39c0f37d029ad57d808103">&#9670;&nbsp;</a></span>unref()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="enumawtk_1_1_ret.html">Ret</a> awtk.AssetsManager.unref </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classawtk_1_1_asset_info.html">AssetInfo</a>&#160;</td>
          <td class="paramname"><em>info</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>释放指定的资源。</p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">info</td><td>资源。</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>返回</dt><dd>返回RET_OK表示成功，否则表示失败。 </dd></dl>

</div>
</div>
<hr/>该类的文档由以下文件生成:<ul>
<li>output/AssetsManager.java</li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
